home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / util / projshad.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-26  |  1.3 KB  |  49 lines

  1. /* projshad.c */
  2.  
  3.  
  4. /*
  5.  * Generate the projection matrix for a projective shadow
  6.  * Borrowed from GLUT distribution's scube demo, written
  7.  * by David Yu.
  8.  */
  9.  
  10.  
  11. /*
  12.  * ground is the equation of the plane onto which the shadow should
  13.  * be projected.
  14.  * light is the homogenious coordinate of the light position.
  15.  */
  16. static void
  17. myShadowMatrix(float ground[4], float light[4])
  18. {
  19.   float dot;
  20.   float shadowMat[4][4];
  21.  
  22.   dot = ground[0] * light[0] +
  23.     ground[1] * light[1] +
  24.     ground[2] * light[2] +
  25.     ground[3] * light[3];
  26.  
  27.   shadowMat[0][0] = dot - light[0] * ground[0];
  28.   shadowMat[1][0] = 0.0 - light[0] * ground[1];
  29.   shadowMat[2][0] = 0.0 - light[0] * ground[2];
  30.   shadowMat[3][0] = 0.0 - light[0] * ground[3];
  31.  
  32.   shadowMat[0][1] = 0.0 - light[1] * ground[0];
  33.   shadowMat[1][1] = dot - light[1] * ground[1];
  34.   shadowMat[2][1] = 0.0 - light[1] * ground[2];
  35.   shadowMat[3][1] = 0.0 - light[1] * ground[3];
  36.  
  37.   shadowMat[0][2] = 0.0 - light[2] * ground[0];
  38.   shadowMat[1][2] = 0.0 - light[2] * ground[1];
  39.   shadowMat[2][2] = dot - light[2] * ground[2];
  40.   shadowMat[3][2] = 0.0 - light[2] * ground[3];
  41.  
  42.   shadowMat[0][3] = 0.0 - light[3] * ground[0];
  43.   shadowMat[1][3] = 0.0 - light[3] * ground[1];
  44.   shadowMat[2][3] = 0.0 - light[3] * ground[2];
  45.   shadowMat[3][3] = dot - light[3] * ground[3];
  46.  
  47.   glMultMatrixf((const GLfloat *) shadowMat);
  48. }
  49.